<?php
	class array2xml {  
    var $xml;  
    function array2xml($array,$encoding='utf-8') {  
          $this->xml="<?xml version='1.0'  encoding='$encoding' ?>"; 
          $this->xml.=$this->_array2xml($array);  
          
    }  
    function getXml() {  
          return $this->xml;  
    }  
    function _array2xml($array) {  
                foreach($array as $key=>$val) {  
                        $num=is_numeric($key);  
                        $num&&$key="item id=\"$key\"";  
                        $this->xml.="<$key>";  
                        $this->xml.=is_array($val)?$this->_array2xml($val):$val;  
                        list($key,)=explode(' ',$key);  
                        $num||$this->xml.="</$key>";  
                        $num&&$this->xml.="</item>";  
                }  
                return $this->xml;  
    }  
} 

	class array2xml_same {  
    var $xml;  
    function array2xml_same($array,$encoding='utf-8',$same) {  
          $this->xml="<?xml version='1.0'  encoding='$encoding' ?>"; 
          $this->xml.=$this->_array2xml_same($array,$same);  
          
    }  
    function getXml() {  
          return $this->xml;  
    }  
    function _array2xml_same($array,$same) {  
                foreach($array as $key=>$val) {  
                        $num=is_numeric($key);  
                        $num&&$key="$same";  
                        $xml.="<$key>";  
                        $xml.=is_array($val)?$this->_array2xml_same($val,$same):$val;  
                        list($key,)=explode(' ',$key);  
                        $num||$xml.="</$key>";  
                        $num&&$xml.="</$same>";  
                }  
                return $xml;  
    }  
} 
?>